package com.ruoyi.front_desk.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.name_category.domain.NameCategory;
import com.ruoyi.name_category.service.INameCategoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 标题名称分类Controller
 *
 * @author ruoyi
 * @date 2024-06-12
 */
@RestController
@RequestMapping("/name_category/name_category")
public class NameCategoryController extends BaseController
{
    @Autowired
    private INameCategoryService nameCategoryService;

    /**
     * 查询标题名称分类列表
     */
    @PreAuthorize("@ss.hasPermi('name_category:name_category:list')")
    @GetMapping("/list")
    public TableDataInfo list(NameCategory nameCategory)
    {
        startPage();
        List<NameCategory> list = nameCategoryService.selectNameCategoryList(nameCategory);
        return getDataTable(list);
    }

    @GetMapping("/listAll")
    public AjaxResult listAll(NameCategory nameCategory)
    {
        List<NameCategory> list = nameCategoryService.selectNameCategoryList(nameCategory);
        return success(list);
    }

    /**
     * 导出标题名称分类列表
     */
    @PreAuthorize("@ss.hasPermi('name_category:name_category:export')")
    @Log(title = "标题名称分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NameCategory nameCategory)
    {
        List<NameCategory> list = nameCategoryService.selectNameCategoryList(nameCategory);
        ExcelUtil<NameCategory> util = new ExcelUtil<NameCategory>(NameCategory.class);
        util.exportExcel(response, list, "标题名称分类数据");
    }

    /**
     * 获取标题名称分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('name_category:name_category:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(nameCategoryService.selectNameCategoryById(id));
    }

    /**
     * 新增标题名称分类
     */
    @PreAuthorize("@ss.hasPermi('name_category:name_category:add')")
    @Log(title = "标题名称分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NameCategory nameCategory)
    {
        return toAjax(nameCategoryService.insertNameCategory(nameCategory));
    }

    /**
     * 修改标题名称分类
     */
    @PreAuthorize("@ss.hasPermi('name_category:name_category:edit')")
    @Log(title = "标题名称分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NameCategory nameCategory)
    {
        return toAjax(nameCategoryService.updateNameCategory(nameCategory));
    }

    /**
     * 删除标题名称分类
     */
    @PreAuthorize("@ss.hasPermi('name_category:name_category:remove')")
    @Log(title = "标题名称分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(nameCategoryService.deleteNameCategoryByIds(ids));
    }
}
